<script setup lang="ts">
defineOptions({
  name: "Dashboard",
  inheritAttrs: false,
});

import { getCardDataAPI } from "@/api/dashboard/index";
import { ICardData } from "@/api/dashboard/types";

const getCardData = async () => {
  const res = await getCardDataAPI();
  cardData.value = res.data;
};

const cardData = ref<ICardData>();

onMounted(() => {
  getCardData();
});
</script>

<template>
  <div class="dashboard-container">
    <div class="main-title">数据看板</div>
    <!-- 数据卡片 -->
    <el-row :gutter="10" class="mt-3">
      <el-col :xs="24" :sm="12" :lg="6">
        <div class="card-item" style="background-color: #add8e6">
          <div class="title">公告数</div>
          <div class="num">{{ cardData?.noticeNum }}</div>
        </div>
      </el-col>

      <el-col :xs="24" :sm="12" :lg="6">
        <div class="card-item" style="background-color: #d2dee7">
          <div class="title">活动数</div>
          <div class="num">{{ cardData?.activityNum }}</div>
        </div>
      </el-col>

      <el-col :xs="24" :sm="12" :lg="6">
        <div class="card-item" style="background-color: #e0f7fa">
          <div class="title">社团数</div>
          <div class="num">{{ cardData?.communityNum }}</div>
        </div>
      </el-col>

      <el-col :xs="24" :sm="12" :lg="6">
        <div class="card-item" style="background-color: #6699cc">
          <div class="title">学生会数</div>
          <div class="num">{{ cardData?.studentUnionNum }}</div>
        </div>
      </el-col>
    </el-row>

    <!-- Echarts 图表 -->
    <el-row :gutter="10" class="mt-4">
      <el-col :sm="24" :lg="8" class="mb-2 echars-item">
        <LineChart
          id="barChart"
          height="350px"
          width="100%"
          class="bg-[var(--el-bg-color-overlay)]"
        />
      </el-col>

      <el-col :xs="24" :sm="12" :lg="8" class="mb-2 echars-item">
        <PieChart
          id="pieChart"
          height="350px"
          width="100%"
          class="bg-[var(--el-bg-color-overlay)]"
        />
      </el-col>

      <el-col :xs="24" :sm="12" :lg="8" class="mb-2 echars-item">
        <PillarChart
          id="radarChart"
          height="350px"
          width="100%"
          class="bg-[var(--el-bg-color-overlay)]"
        />
      </el-col>
    </el-row>
  </div>
</template>

<style lang="scss" scoped>
.dashboard-container {
  position: relative;
  padding: 24px;
  .main-title {
    width: 100%;
    text-align: center;
    font-size: 24px;
    color: #409efe;
  }

  .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  .card-item {
    height: 140px;
    border-radius: 10px;
    display: flex;
    padding: 0 60px;
    justify-content: space-between;
    align-items: center;
    .title {
      font-size: 24px;
      color: rgb(51, 50, 50);
    }
    .num {
      font-size: 34px;
      color: #000000;
    }
  }
  .card-item:hover {
    transform: scale(1.02);
  }
  .echars-item:hover {
    transform: scale(1.02);
  }

  .data-box {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    font-weight: bold;
    color: var(--el-text-color-regular);
    background: var(--el-bg-color-overlay);
    border-color: var(--el-border-color);
    box-shadow: var(--el-box-shadow-dark);
  }

  .svg-icon {
    fill: currentcolor !important;
  }
}
</style>
